package com.huiyujiaoyu.widget;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.huiyujiaoyu.powertime.R;


public class RemindDialog extends Dialog implements View.OnClickListener {

    private TextView tv_content,tv_content1;
    private AppCompatButton btn_right, btn_left;
    private ItemClickListener itemClickListener;
    private ImageView iv_remindSrc;
    //图片url，内容1,2 右边按钮位置，左边按钮位置
    private String content,content1, rightText, leftText;
    private int resd;


    public void setRightText(String rightText) {
        this.rightText = rightText;
        if (btn_right != null)
            btn_right.setText(rightText);
    }


    public void setLeftText(String leftText) {
        this.leftText = leftText;
        if (btn_left != null)
            btn_left.setText(leftText);
    }

    public void setContent(int resd,String content,String content1) {
        this.content = content;
        this.content1 = content1;
        this.resd = resd;
        if (iv_remindSrc != null)
            iv_remindSrc.setBackgroundResource(resd);
        if (tv_content != null)
            tv_content.setText(content);
        if (tv_content1 != null){
            if(TextUtils.isEmpty(content1)){
                tv_content1.setVisibility(View.GONE);
            }else{
                tv_content1.setVisibility(View.VISIBLE);
                tv_content1.setText(content1);
            }
        }
    }
    /**
     * 设置左右按钮字符 和中间内容字符
     * @param context
     * @param content
     * @param theme
     * @param lefttext
     * @param righttext
     */
    public RemindDialog(Context context,int resd, String content,String content1,String lefttext,String righttext,int theme) {
        super(context, theme);
        this.resd = resd;
        this.content = content;
        this.content1 = content1;
        this.leftText = lefttext;
        this.rightText = righttext;
    }


    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_remind);
        this.setCanceledOnTouchOutside(true);
        tv_content = (TextView) findViewById(R.id.tv_remindOne);
        tv_content1 = (TextView) findViewById(R.id.tv_remindTwo);
        btn_right = (AppCompatButton) findViewById(R.id.btn_right);
        btn_left = (AppCompatButton) findViewById(R.id.btn_left);
        iv_remindSrc = (ImageView) findViewById(R.id.iv_remindSrc);
        setContent(resd,content,content1);
        setLeftText(leftText);
        setRightText(rightText);
        btn_right.setOnClickListener(this);
        btn_left.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_right:
                if (itemClickListener != null) {
                    dismiss();
                    itemClickListener.right();
                }
                break;
            case R.id.btn_left:
                if (itemClickListener != null) {
                    dismiss();
                    itemClickListener.left();
                }
                break;
            default:
                break;
        }
    }

    public interface ItemClickListener {
        void left();

        void right();
    }

}
